<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#deviceDataList')}">
        <fieldset>
            <div style="margin:0; padding:1px 5px 5px;">
                <span>设备名称：</span>
                <input type="text" name="deviceName" class="form-control" size="10">
                <span>sn：</span>
                <input type="text" name="sn" class="form-control" size="10">
                <span>所属用户：</span>
                <input type="text" name="ownerName" class="form-control" size="10">
                <span>设备型号：</span>
                <input type="text" name="devicetypeName" class="form-control" size="10">
                <span>上报时间:</span>
                <input type="text" value="" name="createdatestart" data-toggle="datepicker" placeholder="点击选择日期">
                <span>至</span>
                <input type="text" value="" name="createdateend" data-toggle="datepicker" placeholder="点击选择日期">
                &nbsp;<button type="submit" class="btn-green" data-icon="search">开始搜索！</button>
                <button type="reset" class="btn-orange" data-icon="times">重置</button>
                <button onclick="exportData()" type="button" class="btn-orange">导出</button>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table class="table table-bordered" id="deviceDataList" data-toggle="datagrid" data-options="{
        height: '100%',
        local: 'remote',
        showToolbar: true,
        dataUrl: '/sysmanage/devicedata/listdata.do',
        paging: {pageSize:20, pageCurrent:1},
        delUrl:'/sysmanage/devicedata/del.do',
        linenumberAll: false,
        filterThead:false,
        inlineEditMult:false,
        sortAll: false
    }">
        <thead>
        <tr>
            <th data-options="{name:'id',align:'center' }" width="100px">id</th>
            <th data-options="{name:'sn',align:'center'}" width="180px">sn</th>
            <th data-options="{render:'setDeviceName',align:'center'}" width="150px">设备名称</th>
            <th data-options="{render:'setDeviceModel',align:'center'}" width="200px">设备型号</th>

            <th data-options="{name:'report',align:'center'}" width="150px">水位值<br/>(米)</th>
            <th data-options="{name:'voltage',align:'center'}" width="150px">电压值<br/>(伏特)</th>
            <th data-options="{name:'status',align:'center',type:'select',
                    items:[{1:'设备正常'},{2:'低于下限'},{3:'超出上限'},{4:'设备异常'},{5:'设备超时'}]}" width="150px">数据警报
            </th>
            <th data-options="{render:'setUserName',align:'center'}" width="150px">所属用户</th>
            <th data-options="{align:'center',render:'setcreatedate'}" width="200px">上报时间</th>
            <th data-options="{render:'setDeviceInfo',align:'center'}" width="200px">设备信息</th>
        </tr>
        </thead>
    </table>
</div>
<script type="text/javascript">
    var dataTaleTime;

    $(document).ready(function () {
        dataTaleTime=setTimeout("freshDataManage()",3600000);
        $("[title='设备数据管理']").next(".close").click(function () {
            clearTimeout(dataTaleTime);
        })

    })
    function freshDataManage() {
        $('#dg').datagrid('reload')

        dataTaleTime=setTimeout("freshDataManage()",3600000);
    }
    function setDeviceName(value, data) {
        if (data.deviceByDevicesn != null) {
            return data.deviceByDevicesn.devicename;
        }
        return "";
    }
    function setUserName(value, data) {
        if (data.deviceByDevicesn != null) {
            if (data.deviceByDevicesn.deviceownerByOwnerid != null) {
                return data.deviceByDevicesn.deviceownerByOwnerid.name;
            }
        }
        return "";
    }
    function setDeviceInfo(value, data) {
        if (data.deviceByDevicesn != null) {
            return data.deviceByDevicesn.deviceinfo;
        }
    }
    function setDeviceModel(value, data) {
        if (data.deviceByDevicesn != null) {
            return data.deviceByDevicesn.devicemodel;
        }
    }
    function setcreatedate(value, data) {
        return formatDate(new Date(data.createdate));
    }
    function exportData() {
        var deviceName = $("#deviceName").val();
        var ownerName = $("#ownerName").val();
        var devicetypeName = $("#devicetypeName").val();
        var createdatestart = $("#createdatestart").val();
        var createdateend = $("#createdateend").val();

        var form = $("<form>");   //定义一个form表单
        form.attr('style', 'display:none');   //在form表单中添加查询参数
        form.attr('target', '');
        form.attr('method', 'post');
        form.attr('action', "/sysmanage/devicedata/listdataimport");
        var input1 = $('<input>');
        input1.attr('type', 'hidden');
        input1.attr('name', 'deviceName2');
        input1.attr('value', deviceName);
        var input2 = $('<input>');
        input2.attr('type', 'hidden');
        input1.attr('name', 'ownerName2');
        input1.attr('value', ownerName);
        var input3 = $('<input>');
        input3.attr('type', 'hidden');
        input1.attr('name', 'devicetypeName2');
        input1.attr('value', devicetypeName);
        var input4 = $('<input>');
        input4.attr('type', 'hidden');
        input1.attr('name', 'createdatestart2');
        input1.attr('value', createdatestart);
        var input5 = $('<input>');
        input5.attr('type', 'hidden');
        input1.attr('name', 'createdateend2');
        input1.attr('value', createdateend);
        $('body').append(form);  //将表单放置在web中
        form.append(input1);
        form.append(input2);
        form.append(input3);
        form.append(input4);
        form.append(input5); //将查询参数控件提交到表单上
        form.submit();
    }

</script>